/*
 *  cpu.h
 *  iCPU
 *
 *  Created by Kosovan Sasha on 08.10.06.
 *  Licensed under GNU GPL v2
 *
 */ 

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <err.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/time.h>
typedef int  sock_t;

#define CHAT_PORT 1023
#define FILE_PORT 1021

/* general types */
#define u_int8_t unsigned char
#define u_int32_t unsigned int

/* functions */
#define bcopy(src, dst, len)    memcpy(dst, src, len)
#define bzero(b, len)       memset(b, 0, len)
#define err(lev, msg)       fprintf(stderr, "%s\n", msg)

#define WM_FIRSTEXTMSG     0xF0000
#define WM_COMPNAME        WM_FIRSTEXTMSG + 1
#define WM_FIRSTLINK       WM_FIRSTEXTMSG + 2
#define WM_ADDLINK         WM_FIRSTEXTMSG + 3
#define WM_DELLINK         WM_FIRSTEXTMSG + 4
#define WM_OPENLINK        WM_FIRSTEXTMSG + 5
#define WM_LASTLINK        WM_FIRSTEXTMSG + 6
#define WM_LINKERROR       WM_FIRSTEXTMSG + 20
#define WM_LASTEXTMSG      0xFFFFF
#define WM_CHATANSWERING   0xb1

#define WKEY_LEFT       0x25
#define WKEY_UP         0x26
#define WKEY_RIGHT      0x27
#define WKEY_DOWN       0x28
#define WKEY_HOME   0x24
#define WKEY_END    0x23
#define WKEY_DEL    0x2e
#define WKEY_BS     0x08
#define WKEY_DC     0xffbe

struct cpu_packet {
    u_int8_t state;
    u_int32_t msg;
    u_int32_t wparam;
    u_int32_t lparam;
};

struct init_packet {
    u_int8_t msg0;
    u_int8_t msg1;
	u_int8_t msg2;
	u_int8_t msg3;
};
struct cpu_packet2 {
    u_int8_t msg0;
    u_int8_t msg1;
	u_int8_t msg2;
	u_int8_t msg3;
	u_int8_t msg4;
	u_int8_t msg5;
    u_int8_t msg6;
	u_int8_t msg7;
	u_int8_t msg8;
	u_int8_t msg9;
    u_int8_t msg10;
    u_int8_t msg11;
	u_int8_t msg12;
};

struct cpu_packet3 {
    u_int8_t msg0;
    u_int8_t msg1;
	u_int8_t msg2;
	u_int8_t msg3;
	u_int8_t msg4;
	u_int8_t msg5;
    u_int8_t msg6;
	u_int8_t msg7;
	u_int8_t msg8;
	u_int8_t msg9;
    u_int8_t msg10;
    u_int8_t msg11;
	u_int8_t msg12;
	u_int8_t msg13;
    u_int8_t msg14;
	u_int8_t msg15;
	u_int8_t msg16;
	u_int8_t msg17;
	u_int8_t msg18;
    u_int8_t msg19;
	u_int8_t msg20;
	u_int8_t msg21;
	u_int8_t msg22;
    u_int8_t msg23;
    u_int8_t msg24;
	u_int8_t msg25;
};
struct tfiletime {
    u_int32_t ldatetime;
    u_int32_t hdatetime;
};

struct tfiledata {
    u_int32_t size;
    u_int32_t attrs;
    struct tfiletime time_create;
    struct tfiletime time_last_access;
    struct tfiletime time_last_write;
};

struct tgetlinkdata {
    u_int32_t size;
    u_int32_t id;
    u_int32_t image_index;
    struct tfiledata filedata;
    u_int32_t startpos;
    u_int32_t last_block_CRC;
};

struct lcpu_actions {
    void (*funcp_recvc)(int, sock_t, char *);
    char *recvc_data;
    void (*funcp_recvs)(char (*), sock_t, char *);
    char *recvs_data;
    void (*funcp_recvf)(char *, struct tgetlinkdata *, sock_t, char *);
    char *recvf_data;
};


